<?php

/*
 * Following code will update a offer information
 * A offer is identified by offer id (oid)
 */

// array for JSON response
$response = array();

// check for required fields
if (isset($_POST['OfferID']) && isset($_POST['Type']) && isset($_POST['Source']) && isset($_POST['Destination']) && isset($_POST['Over']) && isset($_POST['DepartureFrom']) && isset($_POST['DepartureTo']) && isset($_POST['Note'])) {
    
    $oid = $_POST['OfferID'];
    $type = $_POST['Type'];
    $source = $_POST['Source'];
	$destination = $_POST['Destination'];
	$over = $_POST['Over'];
	$df = $_POST['DepartureFrom'];
	$dt  = $_POST['DepartureTo'];
	$note = $_POST['Note'];

    // include db connect class
    require_once __DIR__ . '/db_connect.php';

    // connecting to db
    $db = new DB_CONNECT();

    // mysql update row with matched pid
    $result = mysql_query("UPDATE Offer SET Type = $type, source = '$source', destination = '$destination', over = '$over', DepartureFrom = '$dp', DepartureTo = '$dt', Note = '$dt' WHERE OfferID = $oid");

    // check if row inserted or not
    if ($result) {
        // successfully updated
        $response["success"] = 1;
        $response["message"] = "Offer successfully updated.";
        
        // echoing JSON response
        echo json_encode($response);
    } else {
        
    }
} else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";

    // echoing JSON response
    echo json_encode($response);
}
?>
